package Arrays方法;

import java.util.Arrays;
import java.util.Comparator;

public class text {
    public static void main(String[] args) {
        int[] arr = {2, 5, 1, 3, 8, 6, 9, 4, 7};
        int i = Arrays.binarySearch(arr, 5);
        System.out.println(i);

        Integer[] arr1 = {2, 5, 1, 3, 8, 6, 9, 4, 7};
        Arrays.sort(arr1, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1 - o2;
            }
        });

        print_for_Arrays(arr1);//正序

        Arrays.sort(arr1, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });

        print_for_Arrays(arr1);//倒序

        //将int类型的数组排序
        int[] arr2 = {12, 15, 11, 13, 18, 16, 19, 14, 17};
        Integer[] arr3 = new Integer[arr2.length];

        for (int i1 = 0; i1 < arr3.length; i1++) {
            arr3[i1] = arr2[i1];
        }

        Arrays.sort(arr3);
        print_for_Arrays(arr3);//正序
        print_for_Arrays(arr2);//正序

        for (int i1 = 0; i1 < arr3.length; i1++) {
            arr2[i1] = arr3[i1];
        }

        print_for_Arrays(arr2);//正序

    }

    private static void print_for_Arrays(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
    }

    private static void print_for_Arrays(Integer[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
    }
}
